<?php
// +----------------------------------------------------------------------
// | sfadmin - Suifeng Administration
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2020 http://suifeng.tech All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: suifeng <1787585212@qq.com>
// +----------------------------------------------------------------------

namespace suifeng\builder;

use suifeng\builder\html\Element;

final class HtmlBuilder
{
    /**
     * 通用元素。
     */
    public static function element($tag = null, $config = [])
    {
        return new Element($tag, $config);
    }

    /**
     * DIV元素。
     */
    public static function div($class = null, $content = null)
    {
        $config['class'] = $class;
        $config['content'] = $content;
        return new Element('div', $config);
    }

    /**
     * SPAN元素。
     */
    public static function span($class = null, $content = null)
    {
        $config['class'] = $class;
        $config['content'] = $content;
        return new Element('span', $config);
    }

    /**
     * 文字。
     */
    public static function plain($html)
    {
        $config['content'] = $html;
        return new Element(null, $config);
    }











    /**
     * 通用元素。
     */
    public static function tag($tag, $config = [])
    {
        return new Element($tag, $config);
    }

    /**
     * 容器。
     */
    public static function container()
    {
        return new Element(null);
    }

    /**
     * 通用按钮。
     */
    public static function button($content, $title = null, $class = null, $config = [])
    {
        if (empty($config['type'])) {
            $config['type'] = 'button';
        }
        $config['title'] = $title;
        $config['class'] = $class;
        $config['content'] = $content;
        return new Element('button', $config);
    }

    /**
     * 提交。
     */
    public static function submit()
    {
        return self::element('button')
            ->cssClass('btn btn-primary')
            ->type('submit')
            ->content('确定');
    }

    /**
     * 取消。
     */
    public static function cancel()
    {
        return self::element('button')
            ->cssClass('btn btn-danger')
            ->type('button')
            ->content('确定')
            ->onclick('javascript:history.back(-1);return false;');
    }

    /**
     * 重置按钮。
     */
    public static function reset()
    {
        return self::element('button')
            ->cssClass('btn btn-danger')
            ->type('reset')
            ->content('重置');
    }

    /**
     * 链接。
     */
    public static function link($href, $content, $title = null, $class = null, $config = [])
    {
        $config['href'] = $href;
        $config['title'] = $title;
        $config['class'] = $class;
        $config['content'] = $content;
        return new Element('a', $config);
    }

    /**
     * 图片。
     */
    public static function image($src, $title = null, $class = null, $config = [])
    {
        $config['src'] = $src;
        $config['title'] = $title;
        $config['class'] = $class;
        return new Element('img', $config);
    }

    /**
     * 图标。
     */
    public static function icon($class, $config = [])
    {
        $config['class'] = $class;
        return new Element('i', $config);
    }

    /**
     * 间隔。
     */
    public static function space()
    {
        $config['style'] = 'margin-bottom: 15px!important;';
        return new Element('div', $config);
    }
}
